package org.hagopa.games.moneypool.msgs.ContentTypes.game;

import java.nio.ByteBuffer;

import org.hagopa.games.moneypool.game.gameobjects.PropertyStatusEnum;
import org.hagopa.games.moneypool.msgs.CommandsEnum;
import org.hagopa.games.moneypool.msgs.IMsgContent;
import org.hagopa.games.moneypool.msgs.ContentTypes.UpdateTypeEnum;

public class PlayerLocation implements IMsgContent{
	
	private int marshalledSize = 0;
	
	private int playerId = 0;
	private int playerCash = 0;
	private int playerPosition = 0;
	private int abId = 0; //absolute Id - independent from Board number
	private int upgradeLevel = 0; // TODO change to Enum
	private int currentCost = 0;
	private int fee = 0;
	private PropertyStatusEnum status = null; //TODO change to Enum
	private int owner = 0; // player id in current Game
	
	
	public int getAbId() {
		return abId;
	}

	public void setAbId(int abId) {
		this.abId = abId;
	}

	public int getUpgradeLevel() {
		return upgradeLevel;
	}

	public void setUpgradeLevel(int upgradeLevel) {
		this.upgradeLevel = upgradeLevel;
	}

	public int getCurrentCost() {
		return currentCost;
	}

	public void setCurrentCost(int currentCost) {
		this.currentCost = currentCost;
	}

	public int getFee() {
		return fee;
	}

	public void setFee(int fee) {
		this.fee = fee;
	}

	public PropertyStatusEnum getStatus() {
		return status;
	}

	public void setStatus(PropertyStatusEnum status) {
		this.status = status;
	}

	public int getOwner() {
		return owner;
	}

	public void setOwner(int owner) {
		this.owner = owner;
	}

	
	

	public int getPlayerId() {
		return playerId;
	}

	public void setPlayerId(int playerId) {
		this.playerId = playerId;
	}

	public int getPlayerCash() {
		return playerCash;
	}

	public void setPlayerCash(int playerCash) {
		this.playerCash = playerCash;
	}

	public int getPlayerPosition() {
		return playerPosition;
	}

	public void setPlayerPosition(int playerPosition) {
		this.playerPosition = playerPosition;
	}

	
	public int getSize() {
		// TODO Auto-generated method stub
		return marshalledSize;
	}

	
	public byte[] marshallToByte() {
		System.out.println("Marshall Player Location");
		ByteBuffer dataArray = ByteBuffer.allocate(256);
		
		byte [] bytes = new byte[256];
		dataArray.putInt(CommandsEnum.UPD_PLAYER.idx());
		dataArray.putInt(UpdateTypeEnum.PLAYER_UPDATE.idx());
		dataArray.putInt(this.playerId);
		dataArray.putInt(this.playerPosition);
		dataArray.putInt(this.playerCash);
		dataArray.putInt(CommandsEnum.UPD_PLAYER.idx());
		dataArray.putInt(UpdateTypeEnum.PROPERTY_UPDATE.idx());
		dataArray.putInt(this.abId);
		dataArray.putInt(this.upgradeLevel);
		dataArray.putInt(this.currentCost);
		dataArray.putInt(this.fee);
		if(this.status != null)
			dataArray.putInt(this.status.idx());
		else
			dataArray.putInt(0);
		dataArray.putInt(this.owner);
		
		dataArray.rewind();
		this.marshalledSize = 48;
		dataArray.get(bytes,0,bytes.length);
		System.out.println("return " + bytes.length + " size");
		return bytes;
		
	}

	
	public boolean unmarshallFromByte(byte[] content) {
		System.out.println("Marshall PLayer Location");
		
		return true;
	}

}
